(function(){
 
    $("pre").each(function(){
        var $this = $(this);
        var code = $this.find("noscript").html();
        $this.find("noscript").html("");
        var wrap = $this.prop("outerHTML");

        code = decodeHTML(code);
        wrap = decodeHTML(wrap);

        var firstLetter = code.match(/^\s*[^\s]/g);
        if (firstLetter && firstLetter.length == 0) return;

        var spaceList = [];
        if (firstLetter && firstLetter.length > 0){
            spaceList = firstLetter[0].match(/ /g);
        }

        wrap = wrap.replace(/\s{2,}/g, "");
        code = code.replace(/^\s*</g, "<").replace(/>\s*$/g, ">").replace(new RegExp(spaceList.join(""), "g"), "");
        wrap = wrap.replace(/<noscript>\s*<\/noscript>/g, "<noscript>" + code + "</noscript>");

        $this.prop("outerHTML", decodeHTML(wrap));
    });

    function encodeHTML(text) {
        return text.replace(/&/g, '&amp').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    }

    function decodeHTML(text) {
        return text.replace(/&amp;/g, '&').replace(/&quot;/g, '/"').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
    }

})();